package com.java.simple.study.jvm.stringtable;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @author zhoujunlin
 * @date 2022年09月03日 22:49
 * @desc 生成一些字符串到文件中 供测试String intern性能
 */
public class GenerateString {

    public static void main(String[] args) throws IOException {
        FileWriter fileWriter = new FileWriter("words.txt");
        for (int i = 0; i < 10_10000; i++) {
            int length = (int) (Math.random() * (10 - 1 + 1) + 1);
            fileWriter.write(getString(length) + "\n");
        }
        fileWriter.close();
    }


    public static String getString(int length) {
        String str = "";
        for (int i = 0; i < length; i++) {
            // 65-90     97-122
            int chrNum = (int) (Math.random() * (90 - 65 + 1) + 65) + (int) (Math.random() * 2) * 32;
            str += (char) chrNum;
        }
        return str;
    }

}
